//
//  SeekEquipmentMoreTable.m
//  OperationPro
//
//  Created by yaxue wang on 2017/2/28.
//  Copyright © 2017年 展鸿科技. All rights reserved.
//

#import "SeekEquipmentMoreTable.h"

@interface SeekEquipmentMoreTable()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataAr;
@end
@implementation SeekEquipmentMoreTable
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //请求设备类型
//        UIView *bgView = [[UIView alloc] initWithFrame:self.bounds];
//        [bgView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.6]];
//        [bgView bk_whenTapped:^{
//            //        [self hideBox];
//        }];
        _dataAr =[[NSMutableArray alloc]init];
        self.tableView=[[UITableView alloc]init];
        self.tableView.delegate=self;
        self.tableView.dataSource=self;
        [self addSubview:self.tableView];
        [CClass HttpRequestTask:YES withUrl:@"select_showEquipSelect" withData:nil notifyError:YES onSuccess:^(BaseModel *model) {
            [_dataAr addObject:@{@"desc":@"全部",@"state":@""}];
            [_dataAr addObjectsFromArray:[model.B_data objectForKey:@"business"]];
            self.tableView.frame=CGRectMake(0, 0, 90, 40*_dataAr.count);
            [self.tableView reloadData];
            
        } onError:^(BaseModel *model) {
            
        }];
        self.tableView.scrollEnabled=NO;
         self.tableView.layer.borderColor=LineColor.CGColor;
         self.tableView.layer.borderWidth=0.5;
        self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        
    }
    
    return self;
    
}
//- (void) hideBox{
//    [self removeFromSuperview];
//}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataAr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cell"]; //出列可重用的cell
    
    //重用的cell
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 1)];
        line.tag=10;
        [cell.textLabel addSubview:line];
    }
    
    UILabel *line=[cell.contentView viewWithTag:10];
    if (indexPath.row==0) {
        line.backgroundColor=[UIColor clearColor];
    }else
    {
        line.backgroundColor=LineColor;
        
    }
  
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.backgroundColor=[UIColor whiteColor];
    //    cell.alpha=0.8;
    NSMutableDictionary*dic=[_dataAr objectAtIndex:indexPath.row];
    cell.textLabel.text=[dic objectForKey:@"desc"];
    cell.textLabel.font=FF(14);
    cell.textLabel.textColor=[UIColor blackColor];
    cell.textLabel.frame=CGRectMake(0, 0, 100, 40);
    cell.textLabel.textAlignment=NSTextAlignmentCenter;
    
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
    if (self.CCellSelect) {
        NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
        [dic setObject:[[_dataAr objectAtIndex:indexPath.row] objectForKey:@"state"] forKey:@"state"];
        [dic setObject:[[_dataAr objectAtIndex:indexPath.row] objectForKey:@"desc"] forKey:@"desc"];

        self.CCellSelect(dic);
    }
}

@end
